<template>
  <el-dialog
    top="30px"
    append-to-body
    width="900px"
    :close-on-click-modal="false"
    :before-close="beforeClose"
    :visible.sync="visible"
  >
    <el-tabs>
      <el-tab-pane label="合同重做">
        <contract-edit :query-id="queryId"></contract-edit>
      </el-tab-pane>
      <el-tab-pane label="委托合同(重做后点击此处修改合同)">
        <contract-entrust-self
          :related-data="related"
          :re-sign="true"
          v-if="+related.gua_type === 2"
        ></contract-entrust-self>
        <contract-entrust v-else :related-data="related" :is-redo="true"></contract-entrust>
      </el-tab-pane>
      <el-tab-pane label="反担保合同(重做后点击此处修改合同)">
        <contract-guard
          :query-id="queryId"
          :related-data="related"
          :is-redo="true"
        ></contract-guard>
      </el-tab-pane>
      <el-tab-pane label="合同重做历史">
        <contract-history :query-id="queryId"></contract-history>
      </el-tab-pane>
    </el-tabs>
  </el-dialog>
</template>

<script>
import ContractEdit from '@/credit/views/union/contract/component/ContractEdit'
import ContractEntrust from '@/credit/views/county/unionProvince/components/ContractEntrust'
import ContractEntrustSelf from '@/credit/views/city/self/components/contractApprove/ContractEntrust'
import ContractGuard from '@/credit/views/county/unionProvince/components/ContractGuard'
import ContractHistory from '@/cadmin/views/org/components/contracApproval/ContractHistory'
export default {
  components: {
    ContractEdit,
    ContractEntrust,
    ContractEntrustSelf,
    ContractGuard,
    ContractHistory,
  },
  props: {
    visible: Boolean,
    queryId: String,
  },
  data() {
    return {
      related: {},
      loading: false,
    }
  },
  computed: {},
  watch: {
    queryId: {
      handler: function () {
        this.getData()
      },
      immediate: true,
    },
  },
  created() {},
  mounted() {},
  methods: {
    getData() {
      this.related = {}
      if (!this.queryId) {
        return
      }
      this.loading = true
      this.$api
        .getData(this.$serviceName, 'customer_related', {
          'customer_related_id.eq': this.queryId,
        })
        .then(res => {
          this.related = res?.data?.[0] ?? {}
        })
        .finally(() => {
          this.loading = false
        })
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handleSuccess() {
      this.$emit('success', true)
      this.beforeClose()
    },
  },
}
</script>

<style lang="scss" scoped></style>
